﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using Fishing.Dal;
using Fishing.Model;

namespace Fishing.Admin
{
    public partial class Ship : System.Web.UI.Page
    {
        ShipDal _dal = new ShipDal();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                DataBind();
            }
            

        }

        protected void btnSelect_Click(object sender, EventArgs e)
        {
            DataBind();
        }

        public void DataBind()
        {
            string sel = txtSelect.Text.Trim();
            string start = txtstart.Text;
            string end = txtend.Text;
            string statu = radbtnStatu.SelectedValue;

            
            List<t_ship> model = _dal.GetShipDataBy(statu, start, end, sel);
            if (model != null)
            {
                rptShip.DataSource = model;
                rptShip.DataBind();
            }
        }

      

        public string getIDs()
        {
            string str_Teamflag = "";
            HtmlInputCheckBox checkBox;
            Repeater rpClass = (Repeater)this.rptShip;

                for (int j = 0; j < rpClass.Items.Count; j++)
                {
                    checkBox = (HtmlInputCheckBox)rpClass.Items[j].FindControl("chk_FlagID");
                    if (checkBox.Checked)
                        str_Teamflag += "'"+checkBox.Value+"'" + ",";
                }
            

            if (str_Teamflag != "")
            {
                //去除最后一个字符
                //str_Teamflag = str_Teamflag.Substring(0, str_Teamflag.Length - 1);
                str_Teamflag = str_Teamflag.Remove(str_Teamflag.Length - 1);
            }
            return str_Teamflag;
        }

        protected void ImgBtnYes_Click(object sender, ImageClickEventArgs e)
        {
            string Ids = getIDs();
            if (Ids.Length > 0)
            {
                
                string statu = "002";
                bool flag = _dal.UpdateDate(Ids, statu);
                if (flag)
                {
                    ClientScript.RegisterStartupScript(this.GetType(), "提示",
                                "<script type='text/javascript'>alert('审核成功！');</script>");
                    DataBind();
                }
                else
                {
                    ClientScript.RegisterStartupScript(this.GetType(), "提示",
                                "<script type='text/javascript'>alert('审核失败！');</script>");
                }

            }
            else
            {
                ClientScript.RegisterStartupScript(this.GetType(), "提示",
                                "<script type='text/javascript'>alert('请选择数据！');</script>");
            }
            
        }

        protected void ImgBtnNo_Click(object sender, ImageClickEventArgs e)
        {
            string Ids = getIDs();
            string statu = "003";
            bool flag = _dal.UpdateDate(Ids, statu);
            if (flag)
            {
                ClientScript.RegisterStartupScript(this.GetType(), "提示",
                            "<script type='text/javascript'>alert('拒绝成功！');</script>");
                DataBind();
            }
            else
            {
                ClientScript.RegisterStartupScript(this.GetType(), "提示",
                            "<script type='text/javascript'>alert('拒绝失败！');</script>");
            }
        }
    }
}